# -*- coding:utf-8 -*-
# @Author: shenyuyu
# @Time: 2023/6/28 17:19
# @File: qu_3_spark_sql_api_text_dataframe.py

from pyspark.sql import SparkSession
from pyspark.sql.types import StructType, StringType

if __name__ == '__main__':
    spark = SparkSession.builder.appName("a").master("local[*]").getOrCreate()
    df = spark.read.format("text").schema("line String").load("file:///tmp/pycharm_project_161/data/sql/people.txt")
    df.show()

    schema = StructType().add("name", StringType(), True)
    df = spark.read.format("text").schema(schema=schema).load("file:///tmp/pycharm_project_161/data/sql/people.txt")
    df.show()